package szwolaiyun.paireach.com.szwolaizhuang.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;

import szwolaiyun.paireach.com.szwolaizhuang.R;
import szwolaiyun.paireach.com.szwolaizhuang.mode.History;

/**
 * Created by Administrator on 2016/7/21.
 */
public class HistoryAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<History>historyArrayList;

    public HistoryAdapter( Context context,ArrayList<History>historyArrayList){
        this.context=context;
        this.historyArrayList=historyArrayList;
    }
    @Override
    public int getCount() {
        return historyArrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return historyArrayList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Mode mode=null;
        if(convertView==null){
            mode=new Mode();
            convertView= LayoutInflater.from(context).inflate(R.layout.item_history,null);
            mode.end_time=(TextView)convertView.findViewById(R.id.end_time);
            mode.work_date=(TextView)convertView.findViewById(R.id.work_date);
            mode.order_code=(TextView)convertView.findViewById(R.id.order_code);
            mode.start_time=(TextView)convertView.findViewById(R.id.start_time);
            convertView.setTag(mode);

        }else{
            mode= (Mode) convertView.getTag();
        }
        if (historyArrayList.get(position).isShowDate()){
            mode.work_date.setVisibility(View.VISIBLE);
            mode.work_date.setText(historyArrayList.get(position).getDate());
        }
        mode.order_code.setText(historyArrayList.get(position).getOrderCode());
        mode.start_time.setText(historyArrayList.get(position).getStartTime());
        mode.end_time.setText(historyArrayList.get(position).getEndTime());
        return convertView;
    }
    class Mode{
        TextView work_date;
        TextView order_code;
        TextView start_time;
        TextView end_time;
    }
}
